import axios from 'axios'
//返回promise对象
export default function ajax(url,data={},methods='GET'){
	return new Promise((resolve,reject)=>{
		let promise;
		if(methods==='GET'){
			let dataStr = '';
			Object.keys(data).forEach(key=>{
				dataStr+= key + '=' + data[key] + '&'
			})
			if(dataStr!==''){
				dataStr=dataStr.substr(0,dataStr.lastIndexOf('&'))
				url = url + '?' +dataStr
			}
			promise=axios.get(url)
		}else{
			promise = axios.post(url,data)
		}
		promise.then(res=>{
			resolve(res.data)
		}).catch(err=>{
			reject(err)
		})
	})
}